package com.legend.utils;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ayakatsune on 14-7-14.
 */
public class Dom4jUtils {
    public static void main(String[] args) {
        // 创建saxreader对象
        SAXReader reader = new SAXReader();
        // 读取一个文件，把这个文件转换成Document对象
        File file=new File("oa/src/config/DatatypeMap.xml");
        Document document = null;
        try {
            document = reader.read(file);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        // 获取根元素
        Element root = document.getRootElement();
        Element element=root.element("DbToJava");
        List<Element> types=element.elements();
        Map map=new HashMap();
        for (Element e:types)
        {
            map.put(e.attribute("key").getText(),e.attribute("value").getText());
            System.out.println(e.attribute("value").getText());
        }
       // System.out.println(element.asXML());
        // 把文档转换字符串
       // String docXmlText = document.asXML();
       // System.out.println(docXmlText);
        System.out.println("---------------------------");
    }

}
